
class LocationUtil {
  /** 定位 */
  static flyToCenter (map, center) {
    if (map) {
      const { lng, lat, height, pitch, roll, heading } = center;
      const positionCartographic = new Cesium.Cartographic(Cesium.Math.toRadians(lng), Cesium.Math.toRadians(lat), height);
      map.camera.flyTo({
        destination: Cesium.Cartographic.toCartesian(positionCartographic),
        orientation: {
          pitch: Cesium.Math.toRadians(pitch),
          roll: Cesium.Math.toRadians(roll),
          heading: Cesium.Math.toRadians(heading)
        },
        duration: 0
      });
    }
  }

  /** 范围定位 */
  static flyToGeometry (map, geometry, distance = 0.8) {
    if (!Array.isArray(geometry)) return;

    if (!map) return;
    let positions = [];
    for (const position of geometry) {
      positions.push(Cesium.Cartesian3.fromDegrees(position[0], position[1]));
    }

    const rec = Cesium.Rectangle.fromCartesianArray(positions);
    const boundingSphere = Cesium.BoundingSphere.fromRectangle3D(rec);
    boundingSphere.radius = boundingSphere.radius * distance;
    map.camera.flyToBoundingSphere(boundingSphere, {
      duration: 0,
      maximumHeight: undefined
    });
  }
}

export default LocationUtil;
